//Source file: D:\\WTK104\\apps\\Toddtris\\src\\com\\toddsoft\\toddtris\\midlet\\DefineKeysCanvas.java

package com.toddsoft.toddtris.midlet;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;

public class DefineKeysCanvas extends Canvas {
    private static final String PROMPTS[] = {"Left","Right","Clockwise","Anticlockwise","Down","Drop"};
    private int index = 0;
    private int keys[] = new int [PROMPTS.length] ;
    private ToddtrisMIDlet tm;
    
    /**
     * @param tm
     */
    DefineKeysCanvas(ToddtrisMIDlet tm) {
        this.tm = tm;     
    }
    
    /**
     * @param keyCode
     */
    public void keyPressed(int keyCode) {
        keys[index] = keyCode;
        if (index == (PROMPTS.length - 1)) {
            tm.keysUpdated(keys);
        } else {
            index++;
            repaint();
        }     
    }
    
    /**
     * @param g graphics object to be rendered
     */
    public void paint(Graphics g) {
        /* blank the page */
        g.setColor(0x00ffffff); // white
        g.fillRect(0, 0, this.getWidth(), this.getHeight());

        /* prompt for key */
        g.setColor(0x00000000); //black
        g.drawString("Press key for", 
                     (int)(this.getWidth() / 2), 
                     (int)(this.getHeight() / 2),
                     Graphics.BOTTOM | Graphics.HCENTER);

        g.drawString(PROMPTS[index], 
                     (int)(this.getWidth() / 2), 
                     (int)(this.getHeight() / 2),
                     Graphics.TOP | Graphics.HCENTER);     
    }
    
    /**
     * Notification handler when canvas hidden.
     * Forces a redraw when canvas is shown again.
     * Signals that the game is paused while the canvas is obscured.
     */
    protected void hideNotify() {
        this.repaint();     
    }
}
